{extend name="public:member" /}
{block name="content"}
<div id="member_content">
	<div class="allWrap">
		<div id="location">
			<div class="allWrap">
				<a href="{$Request.root.true}">首页</a><span>></span><a href="{:url('order_member/index')}">我要评价</a>
			</div>
		</div>	
		
		<div id="comment">
			
			<input name="order_id" type="hidden" value="{$Request.param.id}" />
			
			{if condition="$count eq 1 "}
			<div id="one">
				{volist name="goods_list" id="goods"}
				
				<?php 
						$url=get_goods_type_info(array('type'=>$goods['type'],'goods_id'=>$goods['goods_id']),'url');
						$price=get_goods_type_info(array('type'=>$goods['type'],'price'=>$goods['price']),'price').'*'.$goods['quantity'];
					
				 ?>
				
				<div class="clearfix">
					<input name="goods[{$goods.goods_id}][type]" value="{$goods.type}" type="hidden" />
					<input name="goods[{$goods.goods_id}][order_goods_id]" type="hidden" value="{$goods.order_goods_id}" />
					<div class="goods_img">
						<dl>
							<dt><a href="{$url}"><img src="IMG_ROOT{$goods.image|resize=160,160}" /></a></dt>
							<dd class="goods_name"><a href="{$url}">{$goods.name}</a></dd>
							<dd class="goods_price">{$price}</dd>
						</dl>					
					</div>
					
					<div class="comment_text">
						<textarea name="goods[{$goods.goods_id}][comment]"></textarea>
					</div>
					<div id="star">
						<h1>评分星级</h1>
						<div class="raty"><input class="score" name="goods[{$goods.goods_id}][score]" type="hidden" /></div>
					</div>
					
				</div>
				{/volist}
			</div>
			{else/}
			<div id="more">
				{volist name="goods_list" id="goods"}
				<div class="clearfix">
					<input name="goods[{$goods.goods_id}][type]" type="hidden" value="{$goods.type}" />
					<input name="goods[{$goods.goods_id}][order_goods_id]" type="hidden" value="{$goods.order_goods_id}" />
					<div class="goods_img">
						<dl>
							<dt><a href="{:url('/goods/'.$goods['goods_id'])}"><img src="IMG_ROOT{$goods.image|resize=60,60}" /></a></dt>
							<dd class="goods_name"><a href="{:url('/goods/'.$goods['goods_id'])}">{$goods.name}</a></dd>
							<dd class="goods_price">￥{$goods.price}*{$goods.quantity}</dd>
						</dl>					
					</div>
					<div class="raty">
						<input class="score" name="goods[{$goods.goods_id}][score]" type="hidden" />
					</div>
					<div class="comment_text">
						<textarea name="goods[{$goods.goods_id}][comment]"></textarea>
					</div>
				</div>
				{/volist}
			</div>			
			{/if}
			<button class="buttonred" type="submit">提交</button>
		</div>
		
	</div>	
</div>			
{/block}

{block name="javascript"}
<script src="__PUBLIC__/js/jquery/raty/jquery.raty.min.js"></script>
<script>
	//评星插件
	$('.raty').each(function(i){
		
		$(this).raty({
	   		starHalf: '__PUBLIC__/js/jquery/raty/img/star-half.png',
	   		starOff: '__PUBLIC__/js/jquery/raty/img/star-off.png',
	  		starOn : '__PUBLIC__/js/jquery/raty/img/star-on.png',
	   		click: function(score) {
                $(this).find('.score').val(score);
            }
   		});
		
	});
	
	$('.buttonred').click(function(){
		
	var f=confirm('确认要进行评价吗？');
		if(f==false){
			return false;
		}
		
		$.ajax({
			url: '{:url("Comment/add")}', 
			type: 'post',	
			data:$('#comment input[type=\'hidden\'],#comment textarea'),
			beforeSend: function() {
				art.dialog({
						id:'loading',					
						lock: true,						
					});	
			},	
			complete: function() {
				art.dialog.list['loading'].close();
			},			
			success: function(d) {
				if(d.error){
						art.dialog({
							content:d.error,
							lock: true,						
						});
					}else{					
						art.dialog({				
						    content: d.success,
						    lock: true,	
						    ok: function () {	 		
						 	  window.location.href = d.url;    	
						      return false;
						    }
						});
					}
			},
			error: function(xhr, ajaxOptions, thrownError) {			
				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
			}
		});
		
		
		
	});
	
</script>
{/block}